/**
 * @author 黄波
 * 创建日期：2011Sep 16, 2011
 * TODO// N/A
 */
package com.platform.common.action;

import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.platform.common.bo.CommonBo;
import com.platform.constant.ResponseCode;
import com.platform.pojo.SchoolProperty;

/**
 * 添加学校配置信息
 */
public class AddSchoolPropertyAction extends CommonSupport {

	private String superId;
	private SchoolProperty sp;
	private String msg;
	private boolean success;
	public String getSuperId() {
		return superId;
	}
	public void setSuperId(String superId) {
		this.superId = superId;
	}
	public SchoolProperty getSp() {
		return sp;
	}
	public void setSp(SchoolProperty sp) {
		this.sp = sp;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	@Override
	public String execute() throws Exception {
		if(superId == null || sp == null) {
			msg = ResponseCode.FAILURE_NO_DATA;
		} else {
			CommonBo bo = CommonBo.getInstance();
			sp.setSuperId(Integer.parseInt(superId));//设置父ID
			if(sp.getIsClass() == null) {
				sp.setIsClass(0);
			}
			if(sp.getClassNum() == null) {
				sp.setClassNum(0);
			}
			if(bo.addSchoolProperty(sp)) {
				msg = ResponseCode.SUCCESS_ADD;
			} else {
				msg = ResponseCode.FAILURE_DB_ERROR;
			}
		}

		success = true;
		HashMap map = new HashMap();
		map.put("msg", msg);
		map.put("success", success);
		JSONObject json = JSONObject.fromObject(map);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		out.println(json);
		out.flush();
		out.close();
		return null;
	}
	
}
